histGraphDialog <- function (){
	require(TeachingExtras)
	initializeDialog(title = gettext("Histogram", domain="R-RcmdrPlugin.TeachingExtras"))
	variableBox <- variableListBox(top, Numeric(), title = gettext("Variable (pick one)", domain="R-RcmdrPlugin.TeachingExtras"))
	onOK <- function() {
		variable <- getSelection(variableBox)
		closeDialog()
		if (length(variable) == 0) {
			errorCondition(recall = histGraphDialog, message = gettext("You must select a variable.", domain="R-RcmdrPlugin.TeachingExtras"))
			return()
		}
		title <- tclvalue(titleVariable)
		rel <- tclvalue(relVariable) == "1"
		cum <- tclvalue(cumVariable) == "1"
		poly<- tclvalue(polyVariable)== "1"
		intervals <- tclvalue(intervalsVariable)
		if (intervals == "number") 
			breaks <- as.character(tclvalue(numIntervals))
		else if (intervals == "limits") 
			breaks <- paste("c(", as.character(tclvalue(numIntervals)), ")", sep = "")
		else 
			breaks <- '"Sturges"'
		if (cum) { #Frecuencias acumuladas
			if (rel) {  #Frecuencias relativas
				if (poly) #Con polígono
					command <- paste("histGraph(", ActiveDataSet(), "$", variable, ", breaks=",breaks,",cum=TRUE, rel=TRUE, poly=TRUE, main=\"", title, "\", xlab=\"", variable, "\", col=\"orange\")", sep = "")
					
				else  # Sin polígono
					command <- paste("histGraph(", ActiveDataSet(), "$", variable, ", breaks=",breaks,",cum=TRUE, rel=TRUE, poly=FALSE, main=\"", title, "\", xlab=\"", variable, "\", col=\"orange\")", sep = "")
			}
			else { #Frecuencias absolutas
				if (poly) #Con polígono
					command <- paste("histGraph(", ActiveDataSet(), "$", variable, ", breaks=",breaks,",cum=TRUE, rel=FALSE, poly=TRUE, main=\"", title, "\", xlab=\"", variable, "\", col=\"orange\")", sep = "")
				else  # Sin polígono
					command <- paste("histGraph(", ActiveDataSet(), "$", variable, ", breaks=",breaks,",cum=TRUE, rel=FALSE, poly=FALSE, main=\"", title, "\", xlab=\"", variable, "\", col=\"orange\")", sep = "")
			}
		}
		else { #Frecuencias sin acumular
			if (rel) {  #Frecuencias relativas
				if (poly) #Con polígono
					command <- paste("histGraph(", ActiveDataSet(), "$", variable, ", breaks=",breaks,",cum=FALSE, rel=TRUE, poly=TRUE, main=\"", title, "\", xlab=\"", variable, "\", col=\"orange\")", sep = "")
				else # Sin polígono
					command <- paste("histGraph(", ActiveDataSet(), "$", variable, ", breaks=",breaks,",cum=FALSE, rel=TRUE, poly=FALSE, main=\"", title, "\", xlab=\"", variable, "\", col=\"orange\")", sep = "")
			}
			else { #Frecuencias absolutas
				if (poly) #Con polígono
					command <- paste("histGraph(", ActiveDataSet(), "$", variable, ", breaks=",breaks,",cum=FALSE, rel=FALSE, poly=TRUE, main=\"", title, "\", xlab=\"", variable, "\", col=\"orange\")", sep = "")
				else  # Sin polígono
					command <- paste("histGraph(", ActiveDataSet(), "$", variable, ", breaks=",breaks,",cum=FALSE, rel=FALSE, poly=FALSE, main=\"", title, "\", xlab=\"", variable, "\", col=\"orange\")", sep = "")
			}
		}
		doItAndPrint(command)
		activateMenus()
		tkfocus(CommanderWindow())
	}
	OKCancelHelp(helpSubject = "histGraph")
	optionsFrame <- tkframe(top)
	radioButtons(optionsFrame, name="intervals", buttons = c("automatic", 
			"number", "limits"), labels = gettext(c("Automatic", "Num intervals", "Intervals limits"), domain="R-RcmdrPlugin.TeachingExtras"), 
			title = gettext("Clases definition", domain="R-RcmdrPlugin.TeachingExtras"))
	numIntervals <- tclVar(gettext(""))
	entryIntervals <- tkentry(optionsFrame, width = "10", textvariable = numIntervals)
	relVariable <- tclVar("0")
	relCheckBox <- tkcheckbutton(optionsFrame, variable = relVariable)
	cumVariable <- tclVar("0")
	cumCheckBox <- tkcheckbutton(optionsFrame, variable = cumVariable)
	polyVariable <- tclVar("0")
	polyCheckBox <- tkcheckbutton(optionsFrame, variable = polyVariable)
	titleFrame <- tkframe(top)
	titleVariable <- tclVar(gettext(""))
	titleField <- tkentry(titleFrame, width = "40", textvariable = titleVariable)
	tkgrid(tklabel(titleFrame, text = gettext("Title:", domain="R-RcmdrPlugin.TeachingExtras")), titleField, sticky = "w")
	tkgrid(titleFrame, sticky = "w")
	tkgrid(getFrame(variableBox), sticky = "nw")
	tkgrid(tklabel(top, text = gettext("Options: ", domain="R-RcmdrPlugin.TeachingExtras")), sticky = "w")
	tkgrid(tklabel(optionsFrame, text = gettext("Relative frequencies", domain="R-RcmdrPlugin.TeachingExtras"), justify = "left"), relCheckBox, 
			tklabel(optionsFrame, text = gettext("Cumulative frequencies", domain="R-RcmdrPlugin.TeachingExtras"), justify = "left"), cumCheckBox, sticky = "w")
	tkgrid(tklabel(optionsFrame, text = gettext("Polygon",domain="R-RcmdrPlugin.TeachingExtras"), justify = "left"), polyCheckBox, sticky = "w")
	tkgrid(optionsFrame, sticky = "w")
	tkgrid(buttonsFrame, sticky = "w")
	tkgrid(intervalsFrame, tklabel(optionsFrame, text = gettext("Intervals:", domain="R-RcmdrPlugin.TeachingExtras")), entryIntervals, sticky = "e")
	dialogSuffix(rows = 5, columns = 1)
}